import time

from selenium.webdriver.common.by import By
from common.common import driver

# 个人主页测试
class TestPersonalHomepage():
    url=""
    driver=""

    def __init__(self):
        self.driver=driver.driver
        self.url="http://127.0.0.1:58080/index.html"
        self.driver.get(self.url)

    # 检查自己主页
    def myhomepage(self):
        # 点击主页右上角头像
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown > a").click()
        # 点击我的帖子
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_profile").click()
        # 添加屏幕截图
        driver.getScreeShot()
        # 检查昵称
        time.sleep(0.5)
        text=self.driver.find_element(By.CSS_SELECTOR,"#profile_nickname").text
        assert text=="wyr1234"
        # 检查发帖数
        self.driver.find_element(By.CSS_SELECTOR,"#profile_articleCount")
        # 检查邮箱
        text=self.driver.find_element(By.CSS_SELECTOR,"#profile_email").text
        assert text=="123"
        # 检查发布帖子标题
        text=self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a > strong").text
        assert text=="11"
        # 检查个人介绍
        text=self.driver.find_element(By.CSS_SELECTOR,"#profile_remark").text
        assert text=="123"

        # 返回主页
        self.driver.find_element(By.CSS_SELECTOR,"#nav_board_index > a").click()

    # 检查他人主页
    def someone_homepage(self):
        # 点击他人帖子
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(2) > div > div.col > div.text-truncate > a").click()
        # 点击他人昵称
        time.sleep(0.5)
        self.driver.find_element(By.CSS_SELECTOR,"#article_details_author_name").click()
        # 添加屏幕截图
        driver.getScreeShot()
        # 检查昵称
        time.sleep(0.5)
        self.driver.find_element(By.CSS_SELECTOR,"#profile_nickname")
        # 检查发帖数
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(1)")
        # 检查邮箱
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(2)")
        # 检查个人介绍
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.col-lg-4 > div > div > div > div")

        # 返回主页
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()



